{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|██████████| 64/64 [00:01<00:00, 41.53it/s]\n"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "from glob import glob\n",
    "import numpy as np\n",
    "from tqdm import tqdm\n",
    "\n",
    "datasets=['ecoli_0_vs_1','abalone19','glass-0-4_vs_5','haberman','segment0','pima','glass-0-1-4-6_vs_2','yeast5']\n",
    "files = ['results/result_cart/'+d+'.txt' for d in datasets]\n",
    "\n",
    "df_all=[]\n",
    "names=[]\n",
    "for f in tqdm(files):\n",
    "    name=f.split('/')[-1].split('.')[0]\n",
    "    df = pd.read_table(f, encoding='gbk', header=None)\n",
    "    best_macc = float(df.iloc[-2, :].values[0].split(',')[0].split(':')[-1])\n",
    "    best_std = 0\n",
    "    for i in range(df.shape[0]):\n",
    "        s = df.iloc[i,:].values[0]\n",
    "        if 'Setting' in s:\n",
    "            maccs=[]\n",
    "        elif 'The average mean-accuracy is' in s:\n",
    "            if float(s.split('±')[0].split(': ')[-1])==best_macc:\n",
    "                best_std = np.std(maccs)\n",
    "        elif 'tp' in s and 'tn' in s and 'm-acc' in s and 'auc' in s:\n",
    "            maccs.append(float(s.split(' auc:')[0].split('m-acc:')[-1]))\n",
    "    df_all.append([best_macc, best_std])\n",
    "    names.append(name)\n",
    "    \n",
    "df_all = pd.DataFrame(df_all, index=names, columns=['macc','std'])\n",
    "df_all.to_csv('report/ECUBoost_CART_report.csv')\n",
    "                \n",
    "    \n",
    "# df=pd.read_table(files[0], encoding='gbk',header=None)\n",
    "# print(float(df.iloc[-2,:].values[0].split(',')[0].split(':')[-1]))\n",
    "# df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# used for SVM/BEBS\n",
    "import pandas as pd\n",
    "from glob import glob\n",
    "import numpy as np\n",
    "from tqdm import tqdm\n",
    "\n",
    "datasets=['ecoli_0_vs_1', 'glass1', 'wisconsin', 'pima', 'glass0', 'yeast1', 'haberman', 'vehicle2', 'vehicle1', 'vehicle3', 'vehicle0', 'ecoli1',\n",
    "          'new_thyroid1', 'new_thyroid2', 'ecoli2', 'segment0', 'glass6', 'yeast3', 'ecoli3', 'page_blocks0', 'ecoli-0-3-4_vs_5', 'ecoli-0-2-3-4_vs_5',\n",
    "          'yeast-0-3-5-9_vs_7-8', 'ecoli-0-4-6_vs_5', 'yeast-0-2-5-6_vs_3-7-8-9', 'yeast-0-2-5-7-9_vs_3-6-8', 'ecoli-0-3-4-6_vs_5', 'ecoli-0-3-4-7_vs_5-6',\n",
    "          'ecoli-0-1_vs_2-3-5', 'yeast_2_vs_4', 'ecoli-0-6-7_vs_3-5', 'glass-0-4_vs_5', 'ecoli-0-2-6-7_vs_3-5', 'glass-0-1-5_vs_2', 'yeast_0_5_6_7_9_vs_4',\n",
    "          'vowel0', 'ecoli-0-6-7_vs_5', 'ecoli-0-1-4-7_vs_2-3-5-6', 'glass_0_1_6_vs_2', 'ecoli-0-1_vs_5', 'led7digit-0-2-4-5-6-7-8-9_vs_1', 'glass-0-6_vs_5',\n",
    "          'glass-0-1-4-6_vs_2', 'glass2', 'ecoli-0-1-4-7_vs_5-6', 'cleveland-0_vs_4', 'ecoli-0-1-4-6_vs_5', 'shuttle_c0_vs_c4', 'yeast_1_vs_7', 'ecoli4',\n",
    "          'glass4', 'page_blocks_1_3_vs_4', 'abalone9_18', 'glass_0_1_6_vs_5', 'yeast_1_4_5_8_vs_7', 'yeast_2_vs_8', 'glass5', 'shuttle_c2_vs_c4', 'yeast4',\n",
    "          'yeast_1_2_8_9_vs_7', 'yeast5', 'yeast6', 'ecoli_0_1_3_7_vs_2_6', 'abalone19']\n",
    "files = ['results/BEBS_result/'+d+'.txt' for d in datasets]\n",
    "\n",
    "df_all=[]\n",
    "names=[]\n",
    "for f in tqdm(files):\n",
    "    name=f.split('/')[-1].split('.')[0]\n",
    "    df = pd.read_table(f, encoding='gbk', header=None)\n",
    "    best_macc = float(df.iloc[-1, :].values[0].split(',')[0].split(':')[-1])\n",
    "    best_std = 0\n",
    "    for i in range(df.shape[0]):\n",
    "        s = df.iloc[i,:].values[0]\n",
    "        if 'SVM:' in s:\n",
    "            maccs=[]\n",
    "        elif 'The average mean-accuracy is' in s:\n",
    "            if float(s.split('±')[0].split(': ')[-1])==best_macc:\n",
    "                best_std = np.std(maccs)\n",
    "        elif 'tp' in s and 'tn' in s and 'm-acc' in s:\n",
    "            maccs.append(float(s.split('m-acc:')[-1]))\n",
    "    df_all.append([best_macc, best_std])\n",
    "    names.append(name)\n",
    "    \n",
    "df_all = pd.DataFrame(df_all, index=names, columns=['macc','std'])\n",
    "df_all.to_csv('report/BEBS_CART_report.csv')\n",
    "                \n",
    "    \n",
    "# df=pd.read_table(files[0], encoding='gbk',header=None)\n",
    "# print(float(df.iloc[-2,:].values[0].split(',')[0].split(':')[-1]))\n",
    "# df.head()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
